home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -serious- / comms / other / zelador / sources / zelador_nucleo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-06  |  32.7 KB  |  1,255 lines

  1. /* Núcleo do Zelador    */
  2.  
  3. /* Libraries */
  4. #include <libraries/mui.h>
  5. #include <libraries/gadtools.h> /* for BARLABEL in MenuItem */
  6.  
  7. /* Prototypes */
  8. #ifdef __GNUC__
  9. #include <proto/muimaster.h>
  10. #include <proto/exec.h>
  11. #include <proto/alib.h>
  12. #include <proto/dos.h>
  13. #else
  14. #include <clib/muimaster_protos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/alib_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <pragmas/muimaster_pragmas.h>
  19. #endif /* __GNUC__ */
  20.  
  21. /*  Ansi  */
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24.  
  25. /* incluído por mim.. */
  26. #include <string.h>
  27. #include <time.h>
  28. #include "ZeladorMain.h"
  29. #include "ZeladorGUI.h"
  30. #include "Zelador_Nucleo.h"
  31. #include "ZeladorAREXXinterface.c"
  32. #include "Zelador_Config.c"
  33. #include "ZeladorFrases.h"
  34. #include <exec/exec.h>
  35. #include <devices/timer.h>
  36.  
  37. /* minhas variáveis..    */
  38. int ForcandoEvento;    /* 0-não 1-sim    */
  39. int StatusEvento;        /* passos de 0-idle 1-event req'ed 2-... n-fim    */
  40. long    ConectadoDesdeHHMM;    /* somente válido se AutoMiami estiver habilitado-- Faz parte do Varredura()    */
  41.  
  42. void ProcessamentoCentral (void)
  43. {
  44.     BOOL    running = TRUE;
  45.     ULONG    sinal;
  46.     ULONG SinalVBLANK;
  47.     ULONG MeusSinais;
  48.  
  49. PreparativosIniciaEvento ();
  50. PreparativosEncerraEvento ();
  51.  
  52.     Loga("Zelador started.", 1);
  53.  
  54.    SinalVBLANK = 1 << MeuTimerVBLANK->tr_node.io_Message.mn_ReplyPort->mp_SigBit;
  55.     FazPedidoVBLANK ();
  56.     MeusSinais = 0;
  57.     sinal = 0;
  58.     StatusEvento = 0;    /* its idle    */
  59.     ForcandoEvento = 0;
  60.  
  61.     /* inicializações gerais antes de entrar no loop    */
  62.     InicializaVarsInternas ();    /* ..do zelador_config.h    */
  63.     CarregaConfig ();
  64.     set(MeuApp->CHK_EventosAtivos, MUIA_Selected, DadosConfig.CHK_EventosAtivos);
  65.     TransfereParaGUI ();
  66.     FraseStatus (FraCocando);    /* idle string    */
  67.  
  68.     Varredura ();    /* única utilidade de chamar isso antes é para atualizar o relógio da janela sem delay    */
  69.  
  70.    if (!VerificaSeProgsNaMem ())    /* verifica se Miami e YAM estão na mem    */
  71.        running = FALSE;
  72.  
  73.     while (running)
  74.     {
  75.         if ((MeusSinais&sinal) | !(sinal)) {
  76.         switch (DoMethod(MeuApp->App,MUIM_Application_Input,&sinal))
  77.         {
  78.             case MUIV_Application_ReturnID_Quit:
  79.                 if (!StatusEvento)
  80.                     running = FALSE;
  81.                 break;
  82.  
  83.             /* Insert your code between the "case" statement and comment "end of case ..." */
  84.             case FazerEventoAgora:
  85.                 if (!StatusEvento)    /* forçar evento..    */
  86.                 {
  87.                     ForcandoEvento = 1;    /* indica que está forçando evento    */
  88.                     StatusEvento = 1;
  89.                 }
  90.                 else                        /* interromper evento..    */
  91.                 {
  92.                     if (StatusEvento < 8000)    /* status abortando.    */
  93.                         StatusEvento = 8000;                
  94.                 }
  95.                 break;
  96.             /* end of case FazerEventoAgora */
  97.  
  98.             case ConfGravar:
  99.                 CarregaDaGUI ();
  100.                 TransfereParaGUI ();
  101.                 if (GravaConfig ())
  102.                     MUI_Request (MeuApp->App, 0L, 0L, FraIOError1, FraIOError2, FraIOError3);
  103.                 break;            
  104.  
  105.             /* end of case ConfGravar */
  106.  
  107.             case ConfUsar:
  108.                 CarregaDaGUI ();
  109.                 TransfereParaGUI ();
  110.                 break;
  111.             /* end of case ConfUsar */
  112.  
  113.             case ConfCancelar:
  114.                 TransfereParaGUI ();
  115.                 break;
  116.             /* end of case ConfCancelar */
  117.  
  118.          case AboutPedido:
  119.                 SobreAbout ();
  120.                 break;
  121.          /* end of case AboutPedido */    
  122.  
  123.             case Processar_EFR:
  124.                 Loga("Manual Execution: Email File Request", 0);
  125.                 FraseStatus (FraProcessandoEFR);
  126.                 TrancaGUI();
  127.                 set(MeuApp->BT_FazerEvento, MUIA_Disabled, TRUE);
  128.                 ProcessaFileRequest ();
  129.                 set(MeuApp->BT_FazerEvento, MUIA_Disabled, FALSE);
  130.                 LiberaGUI();
  131.                 FraseStatus (FraCocando);
  132.                 break;
  133.             /* end of case Processar_EFR */
  134.  
  135.             case Processar_RR:
  136.                 Loga("Manual Execution: Robot Reply", 0);
  137.                 FraseStatus (FraProcessandoRR);
  138.                 TrancaGUI();
  139.                 set(MeuApp->BT_FazerEvento, MUIA_Disabled, TRUE);
  140.                 ProcessaAutoReply ();
  141.                 set(MeuApp->BT_FazerEvento, MUIA_Disabled, FALSE);
  142.                 LiberaGUI();
  143.                 FraseStatus (FraCocando);
  144.                 break;
  145.             /* end of case Processar_RR */
  146.  
  147.  
  148.             /* End computing of IDCMP */
  149.  
  150.             default:
  151.                 break;
  152.         }
  153.         }
  154.  
  155.         if (running && (MeusSinais&SinalVBLANK))    /* se foi o vblank q ocorreu..    */
  156.         {
  157.             Varredura();
  158.             WaitIO (&MeuTimerVBLANK->tr_node);
  159.             FazPedidoVBLANK();
  160.         }
  161.         
  162.         if (running && sinal)
  163.         {
  164.             MeusSinais = Wait(sinal|SinalVBLANK);
  165.         }
  166.     }
  167.  
  168.     Loga("Zelador finished.", 0);
  169. }
  170.  
  171. /* abre janela Sobre...    */
  172. void SobreAbout (void)
  173. {
  174.     char FraseTemp[1024];
  175.  
  176.     strcpy (&FraseTemp[0], "\033c\033bZelador 1.22\033n\n©1999 Daniel Mealha Cabrita\n(dancab@iname.com)\nCuritiba - BRAZIL\n\nThis application uses MUI which\nwas written by Stefan Stuntz.\033n");
  177.     strcat (&FraseTemp[0], FraVersNaoReg);
  178.  
  179.     MUI_Request (MeuApp->App, 0L, 0L, FraSobreJan1, FraSobreJan2, &FraseTemp[0]);
  180. }
  181.  
  182. /* código de atualização que deve ser executado de tempos em tempos    */
  183. void Varredura (void)
  184. {
  185.     char    eeps[120];    /* utilizado para retorno de string data-hora    */
  186.  
  187.     PreencheDataHora (&eeps[0], 0);
  188.     set(MeuApp->TXT_DataHoras, MUIA_Text_Contents, &eeps);
  189.  
  190.     /* controla tempos, aborta, inicia eventos, etc.. conforme a hora    */
  191.     if ((StatusEvento) && (StatusEvento < 5000))    /* tem evento acontecendo! (não em status de encerramento)    */
  192.     {
  193.         if (StatusEvento >= 30)    /* se já estiver conectado no Miami..    */
  194.         {
  195.             if ((!(HorarioDeQue (ConectadoDesdeHHMM) & 1)) && !ForcandoEvento)    /* ver se passou do horário de permanecer conectado    */
  196.                 StatusEvento = 8000;
  197.         }
  198.         else
  199.         {
  200.             if ((!(HorarioDeQue (5000) & 2)) && !ForcandoEvento)    /* ver se passou do horário de 'tentar' e não estiver forçando evento..    */
  201.                 StatusEvento = 8000;
  202.         }
  203.     }
  204.  
  205.     switch (StatusEvento)
  206.     {
  207.         case 0:
  208.             /* se os eventos estiverem habilitados..    */
  209.             get(MeuApp->CHK_EventosAtivos, MUIA_Selected, &DadosConfig.CHK_EventosAtivos);
  210.             if (DadosConfig.CHK_EventosAtivos)
  211.             {
  212.                 /* verifica se é hora de fazer evento..    */
  213.                 if (HorarioDeQue (5000) & 2)
  214.                 {
  215.                     Loga("Starting Event", 0);
  216.                     if (!(DadosConfig.CHK_AutoMiami))    /* para evitar ser abortado inadequadamente..    */
  217.                     {
  218.                         StatusEvento = 30;
  219.                         ConectadoDesdeHHMM = RetornaHora ();    /* hora de início    */
  220.                         PreparativosIniciaEvento ();
  221.                     }
  222.                     else
  223.                     {
  224.                         Loga("Dialing...", 0);
  225.                         StatusEvento = 1;
  226.                     }
  227.                 }
  228.             }
  229.             break;
  230.  
  231.         case 1:
  232.             ConectadoDesdeHHMM = RetornaHora ();    /* hora de inicio    */
  233.             PreparativosIniciaEvento ();
  234.             StatusEvento = 10;
  235.             
  236.         case 10:
  237.             if (DadosConfig.CHK_AutoMiami)
  238.             {
  239.                 FraseStatus (FraLigandoMiami);
  240.                 EnviaComandoREXX ("MIAMI.1", "ONLINE");
  241.                 StatusEvento = 20;
  242.             }
  243.             else
  244.                 StatusEvento = 30;
  245.             break;
  246.             
  247.         case 20:
  248.             if (CodRetorno() != 65535)
  249.             {
  250.                 if (!CodRetorno())    /* se CodRetorno() = 0    */
  251.                 {
  252.                     ConectadoDesdeHHMM = RetornaHora ();    /* hora da conexão    */
  253.                     StatusEvento = 25;    /* conectado! (er.. não necessariamente)    */
  254.                 }
  255.                 else
  256.                     StatusEvento = 10;
  257.             }
  258.             break;
  259.  
  260.         case 25:
  261.             /* pede confirmação de conexão do Miami    */
  262.             EnviaComandoREXX ("MIAMI.1", "ISONLINE");
  263.             StatusEvento = 26;
  264.             
  265.         case 26:
  266.             if (CodRetorno() != 65535)
  267.             {
  268.                 if (CodRetorno())    /* se CodRetorno() = 1 (conectado)    */
  269.                 {
  270.                     ConectadoDesdeHHMM = RetornaHora ();    /* hora da conexão    */
  271.                     Loga("Connected.", 0);
  272.                     StatusEvento = 30;    /* EFETIVAMENTE conectado! */
  273.                 }
  274.                 else
  275.                     StatusEvento = 10;    /* naahh..    */
  276.             }
  277.             break;
  278.             
  279.         case 30:
  280.             if (DadosConfig.CHK_EnviarYAM)
  281.             {
  282.                 Loga("Sending mails...", 0);
  283.                 FraseStatus (FraSendYAM);
  284.                 EnviaComandoREXX ("YAM", "mailsendall");
  285.                 StatusEvento = 40;
  286.             }
  287.             else
  288.                 StatusEvento = 50;
  289.             break;
  290.             
  291.         case 40:
  292.             if (CodRetorno() != 65535)
  293.             {
  294.                 if (!CodRetorno())    /* se CodRetorno() = 0    */
  295.                     StatusEvento = 50;    /* enviados os mails!    */
  296.                 else
  297.                     StatusEvento = 30;
  298.             }
  299.             break;
  300.             
  301.         case 50:
  302.             if (DadosConfig.CHK_ReceberYAM)
  303.             {
  304.                 Loga("Receiving mails...", 0);
  305.                 FraseStatus (FraRecYAM);
  306.                 EnviaComandoREXX ("YAM", "mailcheck");
  307.                 StatusEvento = 60;
  308.             }
  309.             else
  310.                 StatusEvento = 70;
  311.             break;
  312.             
  313.         case 60:
  314.             if (CodRetorno() != 65535)
  315.             {
  316.                 if (!CodRetorno())    /* se CodRetorno() = 0    */
  317.                     StatusEvento = 70;    /* recebidos os mails!    */
  318.                 else
  319.                     StatusEvento = 50;
  320.             }
  321.             break;
  322.  
  323.         case 70:
  324.             if (DadosConfig.CHK_Ativo1)
  325.             {
  326.                 Loga("Executing custom #1", 0);
  327.                 FraseStatus (FraCustom1);
  328.                 ExecutaComandoCLI (&DadosConfig.PString1[0], DadosConfig.CHK_Espera1);
  329.             }
  330.             StatusEvento = 80;
  331.             break;
  332.             
  333.         case 80:
  334.             if (DadosConfig.CHK_Ativo2)
  335.             {
  336.                 Loga("Executing custom #2", 0);
  337.                 FraseStatus (FraCustom2);
  338.                 ExecutaComandoCLI (&DadosConfig.PString2[0], DadosConfig.CHK_Espera2);
  339.             }
  340.             StatusEvento = 90;
  341.             break;
  342.             
  343.         case 90:
  344.             if (DadosConfig.CHK_Ativo3)
  345.             {
  346.                 Loga("Executing custom #3", 0);
  347.                 FraseStatus (FraCustom3);
  348.                 ExecutaComandoCLI (&DadosConfig.PString3[0], DadosConfig.CHK_Espera3);
  349.             }
  350.             StatusEvento = 95;
  351.             break;
  352.  
  353.         /* EFR online    */
  354.         case 95:
  355.             if ((DadosConfig.CHK_FileRequest) && (DadosConfig.CHK_EFRScanWhileConnected))
  356.             {
  357.                 Loga("Processing Email File Request...", 0);
  358.                 FraseStatus (FraProcessandoEFR);            
  359.                 ProcessaFileRequest ();
  360.             }
  361.             StatusEvento = 96;
  362.             break;
  363.             
  364.         /* RR online    */
  365.         case 96:
  366.             if ((DadosConfig.CHK_HabilitaRobotReply) && (DadosConfig.CHK_RRScanWhileConnected))
  367.             {
  368.                 Loga("Processing Robot Reply...", 0);
  369.                 FraseStatus (FraProcessandoRR);
  370.                 ProcessaAutoReply ();
  371.             }
  372.             StatusEvento = 97;
  373.             break;
  374.  
  375.         /* envia novamente emails, caso tenha sido selecionado processing while connected    */
  376.         case 97:
  377.             if ((DadosConfig.CHK_EnviarYAM) &&
  378.              ((DadosConfig.CHK_RRScanWhileConnected)
  379.              |(DadosConfig.CHK_EFRScanWhileConnected)))
  380.             {
  381.                 Loga("Sending mails...", 0);
  382.                 FraseStatus (FraSendYAM);
  383.                 EnviaComandoREXX ("YAM", "mailsendall");
  384.                 StatusEvento = 98;
  385.             }
  386.             else
  387.                 StatusEvento = 100;
  388.             break;
  389.             
  390.         case 98:
  391.             if (CodRetorno() != 65535)
  392.             {
  393.                 if (!CodRetorno())    /* se CodRetorno() = 0    */
  394.                     StatusEvento = 100;    /* enviados os mails!    */
  395.                 else
  396.                     StatusEvento = 97;
  397.             }
  398.             break;    
  399.         
  400.         case 100:
  401.             if (DadosConfig.CHK_AutoMiami)
  402.             {
  403.                 Loga("Disconnecting...", 0);
  404.                 FraseStatus (FraDesligaMiami);
  405.                 EnviaComandoREXX ("MIAMI.1", "OFFLINE");
  406.                 StatusEvento = 110;
  407.             }
  408.             else
  409.                 StatusEvento = 200;
  410.             break;
  411.             
  412.         case 110:
  413.             if (CodRetorno() != 65535)
  414.             {
  415.                 if (!CodRetorno())    /* se CodRetorno() = 0    */
  416.                     StatusEvento = 200;    /* DESconectado!    */
  417.                 else
  418.                     StatusEvento = 100;
  419.             }
  420.             break;
  421.  
  422.         /* EFR offline    */
  423.         case 200:
  424.             if ((DadosConfig.CHK_FileRequest) && (!DadosConfig.CHK_EFRScanWhileConnected))
  425.             {
  426.                 Loga("Processing Email File Request...", 0);
  427.                 FraseStatus (FraProcessandoEFR);            
  428.                 ProcessaFileRequest ();
  429.             }
  430.             StatusEvento = 300;
  431.             break;
  432.             
  433.         /* RR offline    */
  434.         case 300:
  435.             if ((DadosConfig.CHK_HabilitaRobotReply) && (!DadosConfig.CHK_RRScanWhileConnected))
  436.             {
  437.                 Loga("Processing Robot Reply...", 0);
  438.                 FraseStatus (FraProcessandoRR);
  439.                 ProcessaAutoReply ();
  440.             }
  441.             StatusEvento = 5000;
  442.             break;
  443.  
  444.         case 5000:    /* FIM!!!!    */
  445.             Loga("Event finished normally.", 0);
  446.             FraseStatus (FraCocando);
  447.             PreparativosEncerraEvento ();
  448.             ForcandoEvento = 0;
  449.             StatusEvento = 0;    /* FIM!    */
  450.             break;
  451.             
  452.         case 8000:    /* ABORTA evento    */
  453.             Loga("Aborting event...", 0);
  454.             FraseStatus (FraAbortando);
  455.             if (DadosConfig.CHK_AutoMiami)
  456.             {
  457.                 Loga("Disconnection is being forced...", 0);
  458.                 ExecutaComandoCLI ("rx \"ADDRESS MIAMI.1 OFFLINE\" >NIL:", 0);
  459.             }
  460.             StatusEvento = 8005;
  461.             break;
  462.  
  463.         case 8005:
  464.             FraseStatus (FraEsperandoFinalizar);
  465.             StatusEvento = 8010;
  466.  
  467.         case 8010:
  468.             if (CodRetorno() != 65535)
  469.             {
  470.                 PreparativosEncerraEvento ();
  471.                 StatusEvento = 0;
  472.             }
  473.             break;
  474.     }
  475.  
  476. }
  477.  
  478. /* retorna hora HHMMSS em minutos -- dos.library    */
  479. long RetornaHora (void)
  480. {
  481.     struct DateStamp DataEstampa;    /* poderá ser necessário alocar isso em PUBLIC MEM    */
  482.     DateStamp (&DataEstampa);
  483.     return long (DataEstampa.ds_Minute);
  484. }
  485.  
  486. /* dado o pointer, o preenche com string de data e hora        */
  487. /* a string receptora deve ser pelo menos 2 * LEN_DATSTRING    */
  488. /* se tipoData=0, string para janela do zelador    */
  489. /* se tipoData<>0, string para LOG                    */
  490. void PreencheDataHora (char * OndeEsta, int tipoData)
  491. {
  492.     struct DateTime DataHora;            /* poderá ser necessário alocar isso em PUBLIC MEM    */
  493.     char DataString [LEN_DATSTRING]; /* idem acima    */
  494.     char HoraString [LEN_DATSTRING];    /* idem acima    */
  495.     char Espac[] = "  ";
  496.     struct tm *tempo;
  497.     time_t tempo2;
  498.     
  499.     if (!tipoData)
  500.     {
  501.         DateStamp (&DataHora.dat_Stamp);
  502.         DataHora.dat_Format = 4;            /* FORMAT_DEF    */
  503.         DataHora.dat_Flags = 0;
  504.         DataHora.dat_StrDay    = 0;
  505.         DataHora.dat_StrDate = DataString;
  506.         DataHora.dat_StrTime = HoraString;    
  507.         DateToStr (&DataHora);
  508.  
  509.         *OndeEsta = char (0);
  510.         strcat (OndeEsta, DataString);
  511.         strcat (OndeEsta, Espac);
  512.         strcat (OndeEsta, HoraString);
  513.     }
  514.     else
  515.     {
  516.         time(&tempo2);
  517.         tempo=gmtime(&tempo2);
  518.         strftime(OndeEsta, 100, "%d/%m/%Y %I:%M:%S", tempo);
  519.     }
  520. }
  521.  
  522. /* preenche campos do iorequest e faz um sendio para o timer.device    */
  523. void FazPedidoVBLANK (void)
  524. {
  525.     MeuTimerVBLANK->tr_node.io_Command = TR_ADDREQUEST;
  526.     MeuTimerVBLANK->tr_time.tv_secs = 1;
  527.     MeuTimerVBLANK->tr_time.tv_micro = 0;
  528.     SendIO (&MeuTimerVBLANK->tr_node);
  529. }
  530.  
  531. /* muda conteúdo do campo 'status' da gui    */
  532. void FraseStatus (char * mifrase)
  533. {
  534.     set(MeuApp->TXT_Status, MUIA_Text_Contents, mifrase);    
  535. }
  536.  
  537. /* ao iniciar evento (forçado ou não)    */
  538. /* ou processar EFR RR q não seja por evento    */
  539. void PreparativosIniciaEvento (void)
  540. {
  541.     TrancaGUI();
  542.     set(MeuApp->BT_FazerEvento, MUIA_Text_Contents, FraAbortarEvento);
  543.     FraseStatus (FraInicioEvento);
  544. }
  545.  
  546. /* desabilita os botões e etc..    */
  547. void TrancaGUI (void)
  548. {
  549.     /* desabilita certos objetos a fim de evitar 'acidentes'    */
  550.     set(MeuApp->MN_Config, MUIA_Menuitem_Enabled, FALSE);
  551.     set(MeuApp->MN_Sobre, MUIA_Menuitem_Enabled, FALSE);
  552.     set(MeuApp->MN_Sair, MUIA_Menuitem_Enabled, FALSE);
  553.     set(MeuApp->BT_Config, MUIA_Disabled, TRUE);
  554.     set(MeuApp->CHK_EventosAtivos, MUIA_Disabled, TRUE);
  555.  
  556.     set(MeuApp->MN_EFR, MUIA_Menuitem_Enabled, FALSE);
  557.     set(MeuApp->MN_RR, MUIA_Menuitem_Enabled, FALSE);
  558.  
  559.     /* fecha janela de config para evitar 'acidentes'    */
  560.     set(MeuApp->Janela_Config, MUIA_Window_Open, FALSE);
  561. }
  562.  
  563. /* habilita os botões e etc..    */
  564. void LiberaGUI (void)
  565. {
  566.     TransfereParaGUI ();    /* restaura gui do setup, caso user tenha modificado (mas não constante nas vars)    */
  567.  
  568.     /* desab eventos (a fim de evitar perda de controle em caso de config errada)    */
  569.     DadosConfig.CHK_EventosAtivos = FALSE;
  570.     set(MeuApp->CHK_EventosAtivos, MUIA_Selected, DadosConfig.CHK_EventosAtivos);
  571.  
  572.     /* torna objetos novamente habilitados    */
  573.     set(MeuApp->MN_Config, MUIA_Menuitem_Enabled, TRUE);
  574.     set(MeuApp->MN_Sobre, MUIA_Menuitem_Enabled, TRUE);
  575.     set(MeuApp->MN_Sair, MUIA_Menuitem_Enabled, TRUE);
  576.     set(MeuApp->BT_Config, MUIA_Disabled, FALSE);
  577.     set(MeuApp->CHK_EventosAtivos, MUIA_Disabled, FALSE);
  578.  
  579.     set(MeuApp->MN_EFR, MUIA_Menuitem_Enabled, TRUE);
  580.     set(MeuApp->MN_RR, MUIA_Menuitem_Enabled, TRUE);
  581. }
  582.  
  583. /* ao encerrar evento (normalmente ou interrompendo) (forçado ou não)    */
  584. /* ou processar EFR RR q não seja por evento    */
  585. void PreparativosEncerraEvento (void)
  586. {
  587.     LiberaGUI();
  588.     set(MeuApp->BT_FazerEvento, MUIA_Text_Contents, FraFazerEvento2);
  589.     FraseStatus (FraCocando);
  590. }
  591.  
  592. /* retorna o qualificador da hora atual    */
  593. /* 0-nada 1-bom para manter-se conectado 3-bom para discar/manter-se conectado    */
  594. /* 2-bom somente para discar    */
  595. /* dado, se disponível, o horário em que conectou c/o Miami    (hora a qual irá considerar como inicial) */
  596. int HorarioDeQue (int HorConectou)
  597. {
  598.     int HoraAtual;
  599.     int QuandoAcaba;    /* horário em q/o evento acaba    */
  600.     int LesFlags;        /* usado p/ composição do código de saída    */
  601.  
  602.     HoraAtual = RetornaHora ();
  603.     LesFlags = 0;
  604.  
  605.     /* verifica se é hora de fazer evento..    */
  606.     if (DadosConfig.Inicio<DadosConfig.TentarAte)
  607.     {
  608.         if ((HoraAtual >= DadosConfig.Inicio) && (HoraAtual <= DadosConfig.TentarAte))
  609.             LesFlags = LesFlags | 2;
  610.     }
  611.     else
  612.     {
  613.         if ((HoraAtual >= DadosConfig.Inicio) || (HoraAtual <= DadosConfig.TentarAte))
  614.             LesFlags = LesFlags | 2;
  615.     }
  616.  
  617.     /* CYC_DuracTempo  0-por duração   1-por horário    */
  618.     if (DadosConfig.CYC_DuracTempo)    /* 1-por horário    */
  619.         QuandoAcaba = DadosConfig.Limite;
  620.     else
  621.     {
  622.         if (HorConectou >= 1440)    /* hora inválida    */
  623.             QuandoAcaba = DadosConfig.Inicio + DadosConfig.Limite;
  624.         else
  625.             QuandoAcaba = HorConectou + DadosConfig.Limite;
  626.  
  627.         if (QuandoAcaba >= 1440)    /* passou da meia-noite, compensa...    */
  628.             QuandoAcaba = QuandoAcaba - 1440;        
  629.     }
  630.  
  631.     /* verifica, finalmente, se está em horário de manter-se conectado...    */
  632.     /* if (DadosConfig.Inicio<DadosConfig.TentarAte)  <-- orig com erro    */
  633.     if (DadosConfig.Inicio<QuandoAcaba)
  634.     {
  635.         if ((HoraAtual >= DadosConfig.Inicio) && (HoraAtual <= QuandoAcaba))
  636.             LesFlags = LesFlags | 1;
  637.     }
  638.     else
  639.     {
  640.         if ((HoraAtual >= DadosConfig.Inicio) || (HoraAtual <= QuandoAcaba))
  641.             LesFlags = LesFlags | 1;
  642.     }
  643.     
  644.     return(LesFlags);
  645. }
  646.  
  647. /* verifica se Miami e YAM estão na mem    */
  648. /* retorna 0-QUIT_Zelador  1-prosseguir    */
  649. int VerificaSeProgsNaMem (void)
  650. {
  651.     long int tempPutz;
  652.     long tempVerifCoisas = 1;
  653.     long tempOpt;
  654.     char tempBuff[512];
  655.  
  656.     while (tempVerifCoisas)
  657.     {    
  658.         tempPutz = 0;
  659.         tempBuff[0] = char(0);
  660.         strcat (&tempBuff[0], FraNaoDetectado1);
  661.  
  662.         if (EnviaEEsperaComandoREXX ("MIAMI.1", "ISONLINE") > 2)
  663.         {
  664.             strcat (&tempBuff[0], FraNaoDetectadoMiami);
  665.             tempPutz = 1;        
  666.         }
  667.         
  668.         /* o abaixo dá erro (-3) por ser comando inválido, mas como -3 < 4...    */
  669.         if (EnviaEEsperaComandoREXX ("YAM", "setfolder 0") != 0)
  670.         {
  671.             strcat (&tempBuff[0], FraNaoDetectadoYAM);
  672.             tempPutz = 1;
  673.         }
  674.  
  675.         if (tempPutz)
  676.         {
  677.             strcat (&tempBuff[0], FraNaoDetectado2);
  678.             if (!(tempOpt = MUI_Request (MeuApp->App, 0L, 0L, FraNaoDetectado3, FraNaoDetectado4, &tempBuff[0])))
  679.                 return(0);
  680.  
  681.             if (tempOpt == 2)
  682.                 return(1);
  683.         }
  684.         else
  685.             return(1);
  686.     }
  687. }
  688.  
  689. /* processa Robot Reply    */
  690. void ProcessaAutoReply (void)
  691. {
  692.     char tempstr[256];
  693.     char tempstrX[256];
  694.     long temploop;
  695.     short int eh_igual_a;    /* 0 a 9 ou -1 se nada    */
  696.     short int tempcont;
  697.     long nummsgs;
  698.     FILE * atsub;    /* arq-texto c/os subjects    */
  699.     char tempComandoYAM[256];    /* usado p/ pegar o remetente da msg    */
  700.     char tempParaQuem[256];        /* contém o remetente da msg                */
  701.  
  702.     MinimizaYAM();    /* minimiza YAM, caso contrário a parte seguinte fica uma carroça    */
  703.     VarreSubjectsYAM ();
  704.  
  705.     EnviaComandoYAM ("setfolder 0", tempstr, 250);
  706.     EnviaComandoYAM ("getfolderinfo MAX", tempstr, 250);
  707.     nummsgs = strtoul (tempstr, 0, 10);
  708.  
  709.     temploop = nummsgs-1;
  710.  
  711.     if (atsub=fopen("t:Zelador.temp", "r"))
  712.     {
  713.         while (temploop>-1)
  714.         {
  715.             fgets (tempstr, 250, atsub);
  716.             ArrumaString(tempstr);
  717.  
  718.             tempcont = 10;
  719.                 
  720.             eh_igual_a = -1;
  721.             while (tempcont)
  722.             {
  723.                 tempcont--;        
  724.                 /* se coincidir subject e estiver ativada a string..    */
  725.                 strcpy(tempstrX, DadosConfig.RR[tempcont].STR);
  726.                 ArrumaString(tempstrX);
  727.                 if ((!stricmp(tempstrX, tempstr)) && DadosConfig.RR[tempcont].CHK)
  728.                     eh_igual_a = tempcont;        
  729.             }
  730.  
  731.             /* se coincidiu com algo, envia msg    */
  732.             if (eh_igual_a != -1)
  733.             {
  734.                 sprintf(tempComandoYAM, "setmail %d;getmailinfo STA", temploop);
  735.                 EnviaComandoYAM (tempComandoYAM, tempParaQuem, 250);
  736.                 
  737.                 if (strcmp(tempParaQuem, "R"))    /* se <>"R" (not replied)..    */
  738.                 {
  739.                     RespondeMsgYAM (temploop, DadosConfig.RR[eh_igual_a].POP, DadosConfig.RR[eh_igual_a].STR, 0L);
  740.                     EnviaComandoYAM ("writequeue", tempstr, 250);    
  741.  
  742.                     /* processa log...    */
  743.                     sprintf(tempComandoYAM, "setmail %d;getmailinfo REP", temploop);
  744.                     EnviaComandoYAM (tempComandoYAM, tempParaQuem, 250);
  745.                     LogRR("Request Processed", 1);
  746.                     LogRR(tempParaQuem, 0);
  747.                     LogRR(DadosConfig.RR[eh_igual_a].STR, 0);
  748.                 }
  749.                 
  750.                 /* apaga a msg */
  751.                 ApagaMsgYAM(temploop);            
  752.             }        
  753.  
  754.             temploop--;
  755.         }
  756.  
  757.         fclose (atsub);
  758.     }
  759.  
  760.     ApagaArqTempSubjectsYAM ();
  761. }
  762.  
  763. /* abre texto de reply p/a msg indicada e indica arquivo-texto
  764.    de resposta.. e arq-texto opcional-- porém NAO fecha (writemailqueue)    */
  765. void RespondeMsgYAM (long qual, char * ArqTxtResposta, char * Assunt, char * ArqTxtExtra)
  766. {
  767.     char tempstr[256];
  768.     char tempstr_frase[256];
  769.     FILE * tempArqResp;    /* arq texto que, efetivamente, será enviado p/o YAM    */
  770.     FILE * tempArqLeitura;    /* arqs lidos..    */
  771.     long tempTamArqResp;
  772.     long tempTamArqLista;
  773.     void * tempMemVec;
  774.     char tempFraseFinal[256];    /* usado p/ escrever 'made by Zelador 1.22 etc e tal'    */
  775.  
  776.     if (tempArqResp=fopen("t:ZeladorResp.temp", "wb"))
  777.     {
  778.         tempTamArqResp=RetornaTamanhoArq(ArqTxtResposta);
  779.         tempTamArqLista=RetornaTamanhoArq(ArqTxtExtra);
  780.  
  781.         if (tempTamArqResp|tempTamArqLista)    /* se não for o caso de ambos serem zero..    */
  782.         {
  783.             if (tempTamArqResp > tempTamArqLista)
  784.                 tempMemVec=AllocVec(tempTamArqResp, 0L);
  785.             else
  786.                 tempMemVec=AllocVec(tempTamArqLista, 0L);
  787.         }
  788.             
  789.         if (tempMemVec)    /* se realmente alocou a memória..    */
  790.         {
  791.             if (tempTamArqResp) /* se tamanho não for nulo..    */
  792.             {
  793.                 if (tempArqLeitura=fopen(ArqTxtResposta, "rb"))
  794.                 {
  795.                     fread(tempMemVec, tempTamArqResp, 1, tempArqLeitura);    
  796.                     fclose(tempArqLeitura);
  797.                     fwrite(tempMemVec, tempTamArqResp, 1, tempArqResp);
  798.                 }
  799.             }
  800.  
  801.             if (ArqTxtExtra)    /* se pointer não for nulo..    */
  802.             {
  803.                 if (tempTamArqLista) /* se tamanho não for nulo..    */
  804.                 {
  805.                     if (tempArqLeitura=fopen(ArqTxtExtra, "rb"))
  806.                     {
  807.                         fread(tempMemVec, tempTamArqLista, 1, tempArqLeitura);    
  808.                         fclose(tempArqLeitura);
  809.                         fwrite(tempMemVec, tempTamArqLista, 1, tempArqResp);
  810.                     }
  811.                 }
  812.             }            
  813.  
  814.             sprintf(tempFraseFinal, "\n\n * reply automatically generated by Zelador 1.22 for Amiga OS\n\n");
  815.             fwrite(tempFraseFinal, strlen(tempFraseFinal), 1, tempArqResp);
  816.         
  817.             FreeVec(tempMemVec);        
  818.         }
  819.  
  820.         fclose(tempArqResp);
  821.     }
  822.  
  823.     sprintf(tempstr_frase, "setmail %d;mailreply", qual);
  824.     EnviaComandoYAM (tempstr_frase, tempstr, 250);
  825.  
  826.     ComandoRexxEspecial ("writesubject", Assunt);
  827.     ComandoRexxEspecial ("writeletter", "t:ZeladorResp.temp");
  828.  
  829.     remove("t:ZeladorResp.temp");
  830. }
  831.  
  832. /* executa comandos 'dfssfd "dfdfdfa"'    */
  833. /* dados: comando e string do comando (nome de arq, subject, etc etc..)    */
  834. void ComandoRexxEspecial (char * comesp, char * dadocomesp)
  835. {
  836.     char frase[256];
  837.  
  838.     sprintf (frase, "rx \"ADDRESS YAM;'%s \"\"%s\"\"'\"", comesp, dadocomesp);
  839.     system (frase);
  840. }
  841.  
  842. /* carrega subjects do folder 0 do YAM na memória    */
  843. /* processa-los um a um com RX é muito lento            */
  844. void VarreSubjectsYAM (void)
  845. {
  846.     system ("rx scrp2 >t:Zelador.temp");
  847. }
  848.  
  849. /* apaga o arquivo gerado pelo 'VarreSubjectsYAM' no T:    */
  850. void ApagaArqTempSubjectsYAM (void)
  851. {
  852.     remove("t:Zelador.temp");
  853. }
  854.  
  855. /* elimina espaços e/ou LFs que estejam no final da string    */
  856. void ArrumaString (char * frase)
  857. {
  858.     int repe;
  859.     short int coisa;
  860.     
  861.     if (repe=strlen(frase))    /* se string >0..    */
  862.     {
  863.         repe--;
  864.         coisa=short int(*(frase+repe));
  865.     
  866.         while (((coisa == 32) || (coisa == 10)) && (repe))
  867.         {
  868.             repe--;
  869.             coisa=short int(*(frase+repe));
  870.         }
  871.  
  872.         if ((coisa == 32) || (coisa == 10))
  873.             *(frase+repe) = char(0);
  874.         else
  875.             *(frase+repe+1) = char(0);
  876.     }
  877. }
  878.  
  879. /* dada uma string, retorna o checksum (byte) dos bytes da mesma    */
  880. UBYTE RetornaCheckSumString (char * frase)
  881. {
  882.     char * tempp=frase;
  883.     UBYTE tempcs=0;
  884.     UBYTE tempv;
  885.  
  886.     while (tempv=UBYTE(*(tempp)))
  887.     {
  888.         tempcs = tempcs + tempv;
  889.         tempp++;    
  890.     }
  891.  
  892.     return(tempcs);
  893. }
  894.  
  895. /* gera ID p/ 'file request por email' dado o email de origem    */
  896. long GeraIDMFR (char * email)
  897. {
  898.     struct DateStamp datasta;
  899.     long meucs;    /* checksum da string fornecida    */
  900.     long tempID;
  901.  
  902.     DateStamp (&datasta);
  903.     meucs = long (RetornaCheckSumString (email));
  904.     tempID=datasta.ds_Days ^ (meucs | (meucs<<7));
  905.     tempID=tempID ^ ((tempID & 0xFF)<<8);
  906.  
  907.     return (tempID);
  908. }
  909.  
  910. /* verifica o ID do 'file request por email' dado o email,    */
  911. /* o ID a verificar e o número de dias q/o ID é válido    */
  912. /* true-se ID válido, false-se não    */
  913. long VerificaIDMFR (char * email, long meuID, long dias)
  914. {
  915.     struct DateStamp datasta;
  916.     long meucs;                /* checksum da string fornecida    */
  917.     long tempDia;            /* dia retornado                        */
  918.     long tempDiff;
  919.  
  920.     DateStamp (&datasta);
  921.     meucs = long (RetornaCheckSumString (email));
  922.  
  923.     tempDia = meuID ^ ((meuID & 0xFF)<<8);
  924.     tempDia = tempDia ^ (meucs | (meucs<<7));
  925.  
  926.     tempDiff=datasta.ds_Days-tempDia;
  927.     if ((tempDiff<dias)&&(tempDiff>=0))    /* para um limite de 5 dias..    */
  928.     {
  929.         return (1);
  930.     }
  931.  
  932.     return (0);
  933. }
  934.  
  935. /* processa EFR    */
  936. void ProcessaFileRequest (void)
  937. {
  938.     char tempstr[256];
  939.     char tempstrX[256];
  940.     long temploop;
  941.     long nummsgs;
  942.     FILE * atsub;    /* arq-texto c/os subjects    */
  943.     char tempSubReduzido[256];    /* subject de comprimento reduzido para comparação primária    */
  944.     char tempSubCriado[256];    /* subject a enviar, com o ID adicionado    */
  945.     char tempParaQuem[256];        /* email do usuário q fez o request    */
  946.     char tempComandoYAM[256];
  947.     void * tempPoinParam;        /* pointer do "5ab875d 2 3 4 7 8..."    */
  948.     long tempIDfornecido;        /* ID lido da mensagem    */
  949.     long tAP[10];    /* array c/os arqs pedidos: 0-null 1-10 nº do arq    */
  950.  
  951.     long tempLimPE;    /* limite bytes por evento    */
  952.     long tempComApg;    /* a partir de XXX bytes, começa a apagar msgs    */
  953.     long tempKBatual=0;    /* KB já feitos nesse evento    */
  954.     long tempKBproposto;    /* tempKBatual + kb pedido msg atual -- para ver se não vai estrapolar    */    
  955.     long tempCont;
  956.     char AttachFrase[768];    /* para o rexx, com o nome do arq e descrição    */
  957.     char tempstrO[256];        /* tempstr sem o '0 0 0 0 0..'    */
  958.     char tempParaLog[256];    /* relação com os números dos arqs, para o LOG    */
  959.     char tempParaLogAux[32];
  960.  
  961.     tempLimPE = strtoul(DadosConfig.STR_MaxPedidoKbEvento, 0, 10);
  962.     tempComApg = strtoul(DadosConfig.STR_RecusaAPartirKB, 0, 10);
  963.  
  964.     MinimizaYAM();    /* minimiza YAM, caso contrário vai ficar uma carroça a parte a seguir    */
  965.     VarreSubjectsYAM ();
  966.  
  967.     EnviaComandoYAM ("setfolder 0", tempstr, 250);
  968.     EnviaComandoYAM ("getfolderinfo MAX", tempstr, 250);
  969.     nummsgs = strtoul (tempstr, 0, 10);
  970.  
  971.     temploop = nummsgs-1;
  972.  
  973.     if (atsub=fopen("t:Zelador.temp", "r"))
  974.     {    
  975.         /* subject a interceptar - nunca muda, então fica aqui    */
  976.         strcpy(tempstrX, DadosConfig.STR_AssuntoIntercepta);
  977.         ArrumaString(tempstrX);
  978.  
  979.         while ((temploop>-1) && nummsgs)
  980.         {
  981.             fgets (tempstr, 230, atsub);
  982.             ArrumaString(tempstr);
  983.             /* cria 'zeros' de segurança na string para evitar que a
  984.                 sujeira seja interpretada como dado pelo sscanf(xxxxxxxx)    */
  985.             strcpy(tempstrO, tempstr);
  986.             strcat(tempstr, " 0 0 0 0 0 0 0 0 0 0 0");    /* dez slots + ID para maior segurança    */
  987.  
  988.             /* AQUI, verifica se o tópico coincide com algo (first request, second request ou nada)    */
  989.  
  990.             /* subject atual, reduzido para comparação    */
  991.             strcpy(tempSubReduzido, tempstr);
  992.             tempSubReduzido[strlen(tempstrX)]=char(0);    /* torna-a do mesmo tamanho que a do assunto    */
  993.  
  994.             if (!stricmp(tempstrX, tempSubReduzido))
  995.             {
  996.                 sprintf(tempComandoYAM, "setmail %d;getmailinfo STA", temploop);
  997.                 EnviaComandoYAM (tempComandoYAM, tempParaQuem, 250);
  998.                 
  999.                 if (strcmp(tempParaQuem, "R"))    /* se <>"R" (not replied)..    */
  1000.                 {
  1001.  
  1002.                 /* *** */
  1003.  
  1004.                 /* pega endereço de email correspondente a msg    */
  1005.                 sprintf(tempComandoYAM, "setmail %d;getmailinfo REP", temploop);
  1006.                 EnviaComandoYAM (tempComandoYAM, tempParaQuem, 250);
  1007.  
  1008.                 if (strlen(tempstrX)==strlen(tempstrO))    /* se for request primário..    */
  1009.                 {
  1010.                     sprintf(tempSubCriado, "%s %p", tempstrO, GeraIDMFR (tempParaQuem));
  1011.                     CriaArqTxtListagem("t:ZeladorList.temp");
  1012.                     RespondeMsgYAM (temploop, DadosConfig.POP_TxtApresentacao, tempSubCriado, "t:ZeladorList.temp");
  1013.                     remove("t:ZeladorList.temp");
  1014.                     EnviaComandoYAM ("writequeue", tempstr, 250);
  1015.  
  1016.                     LogEFR("Primary request processed", 1);
  1017.                     LogEFR(tempParaQuem, 0);
  1018.                     
  1019.                     /* apaga a msg */
  1020.                     ApagaMsgYAM(temploop);
  1021.                 }
  1022.                 else
  1023.                 {
  1024.                     /* tempstr=full tempstrX=só o intercept    */
  1025.                     tempPoinParam=tempstr+strlen(tempstrX);
  1026.                     sscanf(tempPoinParam, "%x %d %d %d %d %d %d %d %d %d %d", &tempIDfornecido,
  1027.                         &tAP[0], &tAP[1], &tAP[2], &tAP[3], &tAP[4],
  1028.                         &tAP[5], &tAP[6], &tAP[7], &tAP[8], &tAP[9]);
  1029.                     /* se ID fornecido for válido, processa request    */
  1030.                     if (VerificaIDMFR (tempParaQuem, tempIDfornecido, strtoul(DadosConfig.STR_MaxDaysValidID, 0, 10)))
  1031.                     {
  1032.                         /* calcula KBs do request da msg atual..    */
  1033.                         tempParaLog[0]=char(0);
  1034.                         tempCont=10;
  1035.                         tempKBproposto=tempKBatual;
  1036.                         while (tempCont)
  1037.                         {
  1038.                             tempCont--;                        
  1039.                             if ((tAP[tempCont]) && (tAP[tempCont]<11))    /* se <> 0 e <11adiciona da contagem de KB    */
  1040.                                 tempKBproposto=tempKBproposto+(RetornaTamanhoArq(DadosConfig.Req[tAP[tempCont]-1].POP)>>10);
  1041.  
  1042.                             /* p/o log..    */
  1043.                             if (tAP[tempCont])    /* se != 0 (válido, portanto)    */
  1044.                             {
  1045.                                 sprintf(tempParaLogAux, "%d ", tAP[tempCont]);
  1046.                                 strcat (tempParaLog, tempParaLogAux);
  1047.                             }
  1048.                         }
  1049.                         
  1050.                         if (tempKBproposto < tempLimPE)    /* se for possível incluir ainda nesse evento..    */
  1051.                         {
  1052.                             /* responde msg..    */
  1053.                             RespondeMsgYAM (temploop, DadosConfig.POP_EnviandoArq, tempstrX, 0L);
  1054.  
  1055.                             /* attacha os arquivos pedidos pelo usuário..    */
  1056.                             tempCont=10;
  1057.                                 
  1058.                             while (tempCont)
  1059.                             {
  1060.                                 tempCont--;                        
  1061.                                 if ((tAP[tempCont]) && (tAP[tempCont]<11))    /* se <> 0 e <11 faz o attach    */
  1062.                                 {
  1063.                                     sprintf (AttachFrase, "rx \"ADDRESS YAM;'writeattach \"\"%s\"\" \"\"%s\"\"'\"", DadosConfig.Req[tAP[tempCont]-1].POP, DadosConfig.Req[tAP[tempCont]-1].STR);
  1064.                                     system (AttachFrase);
  1065.                                 }                            
  1066.                             }
  1067.  
  1068.                             /* finaliza pacote com msg e arquivos attachados    */
  1069.                             EnviaComandoYAM ("writequeue", tempstr, 250);
  1070.  
  1071.                             /* apaga a msg (já foi processada mesmo..)    */
  1072.                             ApagaMsgYAM(temploop);
  1073.  
  1074.                             LogEFR("Secondary request processed", 1);
  1075.                             LogEFR(tempParaQuem, 0);
  1076.                             LogEFR(tempParaLog, 0);
  1077.                             sprintf(tempParaLog, "%d Kb total", (tempKBproposto-tempKBatual));
  1078.                             LogEFR(tempParaLog, 0);
  1079.                             
  1080.                             tempKBatual=tempKBproposto;
  1081.                         }
  1082.                         else
  1083.                         {
  1084.                             if (tempKBproposto > tempComApg)    /* não vai nesse evento e, pior, já entra como 'para apagamento'    */
  1085.                             {
  1086.                                 /* excedeu ambos os limites de KB e será apagado.. */
  1087.                                 LogEFR("Secondary request not processed - Beyond both KB limit. Deleted.", 1);
  1088.                                 LogEFR(tempParaQuem, 0);
  1089.                                 LogEFR(tempParaLog, 0);
  1090.                                 sprintf(tempParaLog, "%d Kb total", (tempKBproposto-tempKBatual));
  1091.                                 LogEFR(tempParaLog, 0);
  1092.  
  1093.                                 /* apaga a msg */
  1094.                                 ApagaMsgYAM(temploop);
  1095.                             }
  1096.                             else
  1097.                             {
  1098.                                 /* excedeu o limite de evento MAS não será apagado.. */
  1099.                                 LogEFR("Secondary request not processed - Beyond KB/event limit. Skipped for later.", 1);
  1100.                                 LogEFR(tempParaQuem, 0);
  1101.                                 LogEFR(tempParaLog, 0);
  1102.                                 sprintf(tempParaLog, "%d Kb total", (tempKBproposto-tempKBatual));
  1103.                                 LogEFR(tempParaLog, 0);                                
  1104.                             }
  1105.                         }                                                            
  1106.                     }
  1107.                     else
  1108.                     {
  1109.                         LogEFR("Secondary request not processed - Invalid ID given by user", 1);
  1110.                         LogEFR(tempParaQuem, 0);
  1111.                         LogEFR(tempstrO, 0);
  1112.                         
  1113.                         /* apaga a msg */
  1114.                         ApagaMsgYAM(temploop);
  1115.                     }
  1116.                 }        
  1117.  
  1118.                 /* *** */
  1119.                 }
  1120.                 else    /* mensagem já respondida; resta apenas deletá-la    */
  1121.                 {
  1122.                     /* apaga a msg */
  1123.                     ApagaMsgYAM(temploop);
  1124.                 }
  1125.             }
  1126.             /* AQUI termina a parte de verificação do tópico    */
  1127.  
  1128.             temploop--;
  1129.         }
  1130.         
  1131.         fclose (atsub);
  1132.     }
  1133.  
  1134.     ApagaArqTempSubjectsYAM ();
  1135. }
  1136.  
  1137. /* retorna o tamanho do arquivo indicado    */
  1138. long RetornaTamanhoArq(char * frase)
  1139. {
  1140.     FILE * tempA;
  1141.     long tempTam = 0;
  1142.     
  1143.     if (tempA=fopen(frase, "rb"))
  1144.     {    
  1145.         fseek(tempA, 0, SEEK_END);
  1146.         tempTam=ftell(tempA);
  1147.         fclose(tempA);
  1148.     }
  1149.  
  1150.     return (tempTam);
  1151. }
  1152.  
  1153. /* cria arq texto c/a listagem dos arquivos do EFR    */
  1154. void CriaArqTxtListagem(char * frase)
  1155. {
  1156.     FILE * ArqList;
  1157.     char * PosBarra;
  1158.     char * PosDoispontos;
  1159.     char * PointCorreto;
  1160.     short int temploop=0;
  1161.     char minhafrase[512];
  1162.     
  1163.     if (ArqList=fopen(frase, "w"))
  1164.     {
  1165.         while (temploop < 10)
  1166.         {
  1167.             if (DadosConfig.Req[temploop].CHK)
  1168.             {
  1169.                 PosBarra = strrchr(DadosConfig.Req[temploop].POP, '/');
  1170.                 PosDoispontos = strrchr(DadosConfig.Req[temploop].POP, ':');
  1171.  
  1172.                 if (PosBarra > PosDoispontos)
  1173.                     PointCorreto = PosBarra;
  1174.                 else
  1175.                     PointCorreto = PosDoispontos;
  1176.                     
  1177.                 if (!PointCorreto)    /* se não existir nem barra nem doispontos..    */
  1178.                     PointCorreto = DadosConfig.Req[temploop].POP;
  1179.                 else
  1180.                     PointCorreto++;
  1181.  
  1182.                 sprintf(minhafrase, "[%d] %s (%dKb)\n    %s\n\n", (temploop+1), PointCorreto, (RetornaTamanhoArq(DadosConfig.Req[temploop].POP) >> 10), DadosConfig.Req[temploop].STR);
  1183.                 fputs(minhafrase, ArqList);
  1184.             }
  1185.             temploop++;
  1186.         }
  1187.  
  1188.         fclose (ArqList);
  1189.     }
  1190. }
  1191.  
  1192.  
  1193. /* log p/ operações genéricas do programa    */
  1194. /* deve cuidar de fornecer a hora e etc    */
  1195. /* se cabeca <> 0, imprime uma marca de 'header' na fte da string    */
  1196. void Loga(char * frase, long cabeca)
  1197. {
  1198.     char    eeps[120];    /* utilizado para retorno de string data-hora    */
  1199.     PreencheDataHora (eeps, 1);
  1200.  
  1201.     if (ArqLogGeral)
  1202.     {
  1203.         if (cabeca)
  1204.             fprintf(ArqLogGeral, "\n%s %s\n", eeps, frase);
  1205.         else
  1206.             fprintf(ArqLogGeral, "%s %s\n", eeps, frase);
  1207.     }
  1208. }
  1209.  
  1210. /* log p/o email file request    */
  1211. /* se cabeca <> 0, imprime uma marca de 'header' na fte da string    */
  1212. void LogEFR(char * frase, long cabeca)
  1213. {
  1214.     char    eeps[120];    /* utilizado para retorno de string data-hora    */
  1215.     PreencheDataHora (eeps, 1);
  1216.  
  1217.     if (ArqLogEFR)
  1218.     {
  1219.         if (cabeca)
  1220.             fprintf(ArqLogEFR, "\n%s %s\n", eeps, frase);
  1221.         else
  1222.             fprintf(ArqLogEFR, "%s %s\n", eeps, frase);
  1223.     }
  1224. }
  1225.  
  1226. /* log p/o robot reply    */
  1227. /* se cabeca <> 0, imprime uma marca de 'header' na fte da string    */
  1228. void LogRR(char * frase, long cabeca)
  1229. {
  1230.     char    eeps[120];    /* utilizado para retorno de string data-hora    */
  1231.     PreencheDataHora (eeps, 1);
  1232.  
  1233.     if (ArqLogRR)
  1234.     {
  1235.         if (cabeca)
  1236.             fprintf(ArqLogRR, "\n%s %s\n", eeps, frase);
  1237.         else
  1238.             fprintf(ArqLogRR, "%s %s\n", eeps, frase);
  1239.     }
  1240. }
  1241.  
  1242. void ApagaMsgYAM(int numeroMe)
  1243. {
  1244.     char tempstr[256];
  1245.     char tcomando[256];
  1246.  
  1247.     sprintf(tcomando, "setmail %d;maildelete FORCE", numeroMe);
  1248.     EnviaComandoYAM (tcomando, tempstr, 250);
  1249. }
  1250.  
  1251. void MinimizaYAM(void)
  1252. {
  1253.     EnviaComandoYAM("hide", 0, 0);
  1254. }
  1255.